package edu.chl.da.ejb.core;

import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 * This class is used as a reference to the hotel reservation that can be done
 * by the hotel booking system.
 * @author Jakob
 */
@Entity
@Table(name = "HOTELRESERVATION")
@NamedQueries({
    @NamedQuery(name = "Hotelreservation.findAll", query = "SELECT h FROM Hotelreservation h"),
    @NamedQuery(name = "Hotelreservation.findByBookingnumber", query = "SELECT h FROM Hotelreservation h WHERE h.hotelreservationPK.bookingnumber = :bookingnumber"),
    @NamedQuery(name = "Hotelreservation.findByFromairport", query = "SELECT h FROM Hotelreservation h WHERE h.hotelreservationPK.fromairport = :fromairport"),
    @NamedQuery(name = "Hotelreservation.findByFromdestination", query = "SELECT h FROM Hotelreservation h WHERE h.hotelreservationPK.fromdestination = :fromdestination"),
    @NamedQuery(name = "Hotelreservation.findByAirplane", query = "SELECT h FROM Hotelreservation h WHERE h.hotelreservationPK.airplane = :airplane"),
    @NamedQuery(name = "Hotelreservation.findBySeatno", query = "SELECT h FROM Hotelreservation h WHERE h.hotelreservationPK.seatno = :seatno"),
    @NamedQuery(name = "Hotelreservation.findBySeatrow", query = "SELECT h FROM Hotelreservation h WHERE h.hotelreservationPK.seatrow = :seatrow"),
    @NamedQuery(name = "Hotelreservation.findByCustomer", query = "SELECT h FROM Hotelreservation h WHERE h.hotelreservationPK.customer = :customer")})
public class Hotelreservation implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected HotelreservationPK hotelreservationPK;
    @JoinColumns({
        @JoinColumn(name = "FROMAIRPORT", referencedColumnName = "FROMAIRPORT", insertable = false, updatable = false),
        @JoinColumn(name = "FROMDESTINATION", referencedColumnName = "FROMDESTINATION", insertable = false, updatable = false),
        @JoinColumn(name = "AIRPLANE", referencedColumnName = "AIRPLANE", insertable = false, updatable = false),
        @JoinColumn(name = "SEATNO", referencedColumnName = "SEATNO", insertable = false, updatable = false),
        @JoinColumn(name = "SEATROW", referencedColumnName = "SEATROW", insertable = false, updatable = false),
        @JoinColumn(name = "CUSTOMER", referencedColumnName = "CUSTOMER", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private Reservation reservation;

    public Hotelreservation() {
    }

    public Hotelreservation(HotelreservationPK hotelreservationPK) {
        this.hotelreservationPK = hotelreservationPK;
    }

    public Hotelreservation(int bookingnumber, String fromairport, String fromdestination, int airplane, int seatno, int seatrow, String customer) {
        this.hotelreservationPK = new HotelreservationPK(bookingnumber, fromairport, fromdestination, airplane, seatno, seatrow, customer);
    }

    public HotelreservationPK getHotelreservationPK() {
        return hotelreservationPK;
    }

    public void setHotelreservationPK(HotelreservationPK hotelreservationPK) {
        this.hotelreservationPK = hotelreservationPK;
    }

    public Reservation getReservation() {
        return reservation;
    }

    public void setReservation(Reservation reservation) {
        this.reservation = reservation;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (hotelreservationPK != null ? hotelreservationPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Hotelreservation)) {
            return false;
        }
        Hotelreservation other = (Hotelreservation) object;
        if ((this.hotelreservationPK == null && other.hotelreservationPK != null) || (this.hotelreservationPK != null && !this.hotelreservationPK.equals(other.hotelreservationPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "edu.chl.da.ejb.core.Hotelreservation[hotelreservationPK=" + hotelreservationPK + "]";
    }

}
